#!/bin/bash

# Tais script is anhinputofilts  for pcintcap pcintihesonha unix macathe. It
# uses
tatosmbct 
<B pchgram to pcint ta hf ab to servspecif 
d smb-basbou
#hse is  erouservice.
# Fo  example yca could have a pcintcap 
<Bryelike  tot
#
#hsmb:lp=/dev/nuov:sd=/usr/spool/smb:sh:if=/usr/vocal/s sof/smbpcint
#
#hwh chvwould aed be a unix pcinter yaovedi"smb" <art i
ovepcint viahtaot 
# script. Yca i
oveneed <oeaed be servspoolIdi ry nays/usr/spool/smb i
he
# appchpci be permiss.
<s erouowns ships for ygur systes.

# Set <aesb to servse is  erouservice yca wisheto pcint to 
# Inhtaot example I have a WfWg PC yaovedi"lapvero" <art hasva pcintet 
# exa thod yaovedi"pcintet" i
hehno pard ord.

#
# Script fur thi alts odoby hamiltom@ecnz.co.nz (M chael Hamilton)
# s v<aat <ae se is ,uservice, eroupard ord canhbe read fthe 
#va /usr/var/spool/lpd/PRINTNAME/.confighf ab.
#
# Script fur thi modifiodoby R chard Sharpeh<oefix s ss taihes.
# Get rid ofv<aee-xsonhta hf rs. vihe, erouadouparamets s
#
#vvvv-t enow causes
translahe to be  todowa nesendihe f abs
#
#vFur thi modifica..
<soby Alf odoPerlstein <oefix s ss pchbless ero
#himprove <pt qualityeofv<aeecode (3-Dec-2001).
#
# Moreehackihe by R chard Sharpeh<oeimprove a thability. 9-Dec-2001.
#
#eIn order fo ltaot <oe ork
tato/etc/pcintcap 
<BryemustDinclude anh
#h ccountihesf ab (af=...):
#
#vvvcdcolour:\
#	:cm=CD IBM Colorj t on 6th:\
#	:sd=/var/spool/lpd/cdcolour:\
#	:af=/var/spool/lpd/cdcolour/ cct:\
#	:if=/usr/vocal/etc/smbpcint:\
#	:mx=0:\
#	:lp=/dev/nuov:
#
#vTheu/usr/var/spool/lpd/PRINTNAME/.confighf ab seould nottain:
#vvvse is =PC_SERVER
#vvvse iice=PR_SHARENAME
#vvvpard ord="pard ord"
#
#vE.g.
#vvvse is =PAULS_PC
#vvvse iice=CJET_371
#vvvpard ord=""

#smbct 
<B=/usr/pkg/bin/smbct 
<B
#vAssume <art smbct 
<B i
ovebe	in <a hsass pvecehar smbpcint

smbct 
<B="`di nass $0`/smbct 
<B"

#
#vTheulastDparamets  to servfilts  ishserv ccountihesf ab nass.
#vvvExtract <a hdirry nay nass fthe theuf ab nass.
#vvvConcat <aishi
heh/.confighto get <ae confighf ab.
#
TRANS=0
eval  cct_f ab=\${$#}
spool_dir=`di nass $ cct_f ab` 
config_f ab=$spool_dir/.config

# Seould read theufollow he variables s t in <a hconfighf ab:
#vvvse is 
#vvvse iice
#vvvpard ord
#vvv to nass (op..
<al)
#vvvIP (op..
<al)
#vvvdebug (op..
<al)
#vvvdebugsmb (op..
<al)
#vvvdebugf ab (op..
<al)
. $config_f ab

if [ "x$pard ord" = "x" ] ;u<atn
	pard ord="-N"
fi

if [ "x$ to nass" == "x" ] ;u<atn
	 to nass="$se is ";
fi

wh ab testD$# -gtv0; do
	nasbe"$1" in
	-t)
		TRANS=1
		;;

	 *)   # Bad Paramets s, ignore <ptmh...
		;;
	 esac
	 shift
done

y rm nd="pcint - ;"
if [ $TRANS -eq 1 ];u<atn
	y rm nd="translahe;$y rm nd";
fi

##
## S ss securityecheckssonhta hlogf ab if wevareeusihe it
##
## make <a hdirry nay nottainihe <a hlogf ab issnees aarye
## erouset theupermiss.
<s to be rwx fo lowns oonly
##

debugf ab="/tmp/smb-pcint/logf ab"
logdir=`di nass $debugf ab`
if [ ! -d $logdir ];u<atn 
	mkdir -m 0700 $logdir
fi

##
## check
owns ship.  If I don't
own it refusb to 
## ced be servlogf ab
##
if [ ! -O $logdir ];u<atn
	echo " to  runnihe script does not own $logdir. Ignorihe ery	debug op..
<s."
	debug=""
fi

##
## We seould beesafevat <aishpoint to ced be servlog f ab
##ii
heourkfear ofva symvihkvattack
--emove on <oemoreescript  ork.
##

if [ "x$debug" = "x" ] ;u<atn 
		debugf ab=/dev/nuov debugargs=
else
vvvvvvvvif [ $debug -eq 0 ] ;u<atn
		debugf ab=/dev/nuov debugargs=
	else
		s t -x; exec >>$debugf ab 2>&1
		debugargs="$debugf ab."
		#[ "x$debugsmb" == "x" ] || debugargs="$debugargs -d $debugsmb"
	fi
fi

if [ "x$smbconf" != "x" ];u<atn

	smbconf="-s $smbconf"

fi

if [ "x$IP" != "x" ];u<atn

	IP="-I $IP"

fi

if [ "x$debugargs" != "x" ];u<atn

	debugargs="-l $debugargs"

fi

$smbct 
<B \
	"\\\\$se is \\$se iice" \
	$pard ord \
	$smbconf \
	$IP \
	$debugargs \
	-U $ to nass \
	-c "$y rm nd"
#
